<h2>Plugins</h2>

<p>
	When editing content through the Control Panel (like pages and news articles) or building themes, there will be certain
	tags available to the user and designer. These are called Plugins and can represent data or be a way to add extra functionality
	to the page, like inserting <a href="developers/widgets.html">Widget areas</a>, displaying settings or user details.
</p>

<p>There are two types of Plugins you can create, but they are both basically the same thing:</p>

<ol>
	<li>Standalone Plugin: <def>addons/plugins/<em>pluginname</em>.php</def></li>
	<li>Modular Plugin: <def>addons/modules/<em>modulename</em>/plugin.php</def></li>
</ol>

<h3>What is the difference?</h3>

<p>
	A Modular Plugin would be something that compliments a custom module you have built, while a Standalone Plugin would be something
	general like a Google Maps plugin or a way to list out Tweets in your own syntax.
</p>

<h3>How do Plugins differ from Widgets?</h3>

<p>
	A Plugin is pure syntax, a <a href="developers/widgets.html">Widget</a> is entirely self contained. That means you can drag and drop Widgets into an area and it will know exactly what to do
	by itself. Plugins give people a lot more freedom if they know how to use them and are capable of editing HTML.
</p>

<h3>Example Plugin Definition</h3>

<p>This is the Session plugin which can be found here <def>system/pyrocms/plugins/session.php</def></p>

<pre><code class="php">&lt;?php defined('BASEPATH') or exit('No direct script access allowed');
/**
 * Session Plugin
 *
 * Read and write session data
 *
 * @package		PyroCMS
 * @author		PyroCMS Dev Team
 * @copyright	Copyright (c) 2008 - 2011, PyroCMS
 *
 */
class Plugin_Session extends Plugin
{
	/**
	 * Data
	 *
	 * Loads a piece of session data
	 *
	 * Usage:
	 * {pyro:session:data name="foo"}
	 *
	 * @param	array
	 * @return	array
	 */
	function data()
	{
		$name = $this->attribute('name');
		$value = $this->attribute('value');

		// Mo vaue? Just getting
		if ($value !== NULL)
		{
			$this->session->set_userdata($name, $value);
			return;
		}

		return $this->session->userdata($name);
	}

	/**
	 * Flash
	 *
	 * Loads a piece of flashdata
	 *
	 * Usage:
	 * {pyro:session:flash name="foo"}
	 *
	 * @param	array
	 * @return	array
	 */
	function flash()
	{
		$name = $this->attribute('name');
		$value = $this->attribute('value');

		// No value? Just getting
		if ($value !== NULL)
		{
			$this->session->set_flashdata($name, $value);
			return;
		}

		return $this->session->flashdata($name);
	}
}

/* End of file theme.php */</code></pre>

<h3>Example usage</h3>

<p>All you need to do for this to work is open up a theme, page, article, etc and enter:</p>

<pre><code class="html">{pyro:session:data name="foo" value="bar"}</code></pre>

<p>Then somewhere else you could do this:</p>

<pre><code class="html">{pyro:session:data name="foo"}</code></pre>

<p>That will display bar on your page. Obviously this is a very simple example, but by loading up your Module Models, you could do all sorts of things.</p>

<h3>Installing? Loading?</h3>

<p>Nope! You don't need to install Plugins, or worry about loading them. Just use them and whatever is returned by the plugin method will replace the tag in your theme, page, article, etc.</p>